#!/usr/bin/perl

# Test group checker using environment method.  Access will be granted if
# the login and the group name are identical, and will be rejected otherwise.
#
# This authenticator does copious logging by writing all sorts of stuff to
# STDERR.  A production authenticator would not normally do this.

# Get the name of this program
$prog= join ' ',$0,@ARGV;

# Get the user name
$user= $ENV{USER};

# Get the group names
$groups= $ENV{GROUP};

# Dump the environment to the error_log file
foreach $env (keys(%ENV))
{
    print STDERR "$prog: $env=$ENV{$env}\n";
}

# Loop through groups
foreach $group (split ' ', $groups)
{
    # Accept the login if the user name matchs the group name
    if ($user eq $group)
    {
	print STDERR "$prog: login name matches group name - Accepted\n";
	exit 0;
    }
}

print STDERR "$prog: login name doesn't match any group name - Rejected\n";
exit 1;
